package com.net.xpay.common.manager.impl;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.net.common.dao.BasicMapper;
import com.net.common.dao.Page;
import com.net.xpay.common.dao.SafePayExcelTemplateMapper;
import com.net.xpay.common.domain.SafePayExcelTemplate;
import com.net.xpay.common.manager.SafePayExcelTemplateManager;
import com.net.common.manager.AbstractManager;
import com.net.xpay.core.model.SafePayExcelTemplateSearchModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
public class SafePayExcelTemplateManagerImpl extends AbstractManager<SafePayExcelTemplate> implements SafePayExcelTemplateManager{

    @Autowired
    private SafePayExcelTemplateMapper mapper;


    @Override
    protected BasicMapper<Long, SafePayExcelTemplate> getMapper() {
        return mapper;
    }

    @Override
    public SafePayExcelTemplate findByName(Long userId, String name) {
        Preconditions.checkArgument(userId != null && !Strings.isNullOrEmpty(name));

        SafePayExcelTemplate condition = new SafePayExcelTemplate();
        condition.setUserId(userId);
        condition.setName(name);
        return getByCondition(condition);
    }

    @Override
    public SafePayExcelTemplate findById(Long userId, Long id) {
        Preconditions.checkArgument(userId != null && id != null);
        SafePayExcelTemplate condition = new SafePayExcelTemplate();
        condition.setUserId(userId);
        condition.setId(id);
        return getByCondition(condition);
    }

    @Override
    public List<SafePayExcelTemplate> search(SafePayExcelTemplateSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        Page page = new Page(searchModel);
        page.addOrder("id", "desc");
        return nonEmptyList(mapper.search(searchModel, page));
    }

    @Override
    public long searchCount(SafePayExcelTemplateSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return mapper.searchCount(searchModel);
    }

    @Override
    public List<SafePayExcelTemplate> list(SafePayExcelTemplateSearchModel searchModel) {
        return nonEmptyList(mapper.list(searchModel));
    }
}
